package JDBC;

import java.sql.Connection;
import java.sql.DriverManager;

public class DBConn {
	static{
		try{
			Class.forName("com.mysql.jdbc.Driver");
			System.out.println("驱动加载成功");
		}catch(Exception ex){
			System.out.println("驱动加载失败");
			ex.printStackTrace();
			}
	}
	
	public static Connection getConn(){
		try{
			Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/hssystation?useUnicode=true&characterEncoding=UTF-8", "root", "kj2016");
			System.out.println("获取数据库连接成功");
			return conn;
		}catch(Exception ex){
			System.out.println("获取数据库连接失败");
			ex.printStackTrace();
			return null;
		}
	}
	
	public static void close(Connection conn){
		if(conn != null){
			try{
				conn.close();
			}catch(Exception ex){}
		}
	}
}
